import * as types from './type'
import {fromJS} from "immutable";

const defaultData = fromJS({
    searchValue: '',
    searchFocused: false,
    TopSearchWords: [],
    TopSearchFocused: false,
    shouldTopSearchOpen: false,
    visible:true,
});
// eslint-disable-next-line
export default (state = defaultData, action) => {
    let newVal = action.value;
    if (newVal !== undefined) {
        switch (action.type) {
            // header 搜索框
            case types.HEADER_SEARCH_INPUT:
                return state.set('searchValue', newVal);
            //    search框聚焦
            case types.HEADER_SEARCH_FOCUS:
                return state.set('searchFocused', newVal);
            // 控制是否隐藏
            case types.HEADER_TOP_VISIBLE:
                return state.set('visible',newVal);

            case types.HEADER_SEARCH_INIT:
                return state.set('TopSearchWords', newVal);

            case types.HEADER_TOP_SEARCH_FOCUSED:
                return state.set('TopSearchFocused', newVal);

            case types.HEADER_TOP_SEARCH_OPEN:
                return state.set('shouldTopSearchOpen', newVal);
            default:
                return state;
        }
    }
    return state;
}
